<?php

namespace Admin\Form;

use Zend\Form\Form;
use Zend\InputFilter;
use Zend\Form\Element\File;
class ProductForm extends Form
{
    public function __construct($name = null, $options = array())
    {
        parent::__construct($name, $options);
        $this->setAttribute('enctype', 'multipart/form-data');

        $this->add(array(
            'name' => 'id',
            'attributes' => array(
                'type'  => 'hidden',
                'class'=>'form-control'
            ),
        ));
        $this->add(array(
        		'name' => 'name',
        		'type' => 'Text',
        		'attributes' => array(
        				'id' => 'name',
        				'class' => 'form-control',
        		        "required" => "required"
        		)
        ));
        $this->add(array(
        		'name' => 'video',
        		'type' => 'Text',
        		'attributes' => array(
        				'id' => 'video',
        				'class' => 'form-control',
        		         "required" => "required"
        		)
        ));
        $this->add(array(
        		'name' => 'category_id',
        		'type' => 'Text',
        		'attributes' => array(
        				'id' => 'video',
        				'class' => 'form-control',
//         		         "required" => "required"
        		)
        ));
        $this->add(array(
            'name' => 'desc',
            'type' => 'TextArea',
            'attributes' => array(
                'id' => 'desc',
                'class' => 'form-control  faq_txt_content',
                'rows' => '4',
                'columns' => '10',
            )
        ));
        $this->add(array(
            'name' => 'short_desc',
            'type' => 'TextArea',
            'attributes' => array(
                'id' => 'short_desc',
                'class' => 'form-control  faq_txt_content',
                'rows' => '4',
                'columns' => '10',
            )
        ));
        $this->add(array(
        		'name' => 'banner',
        		'type' => 'file',
        		'attributes' => array(
        				'id' => 'banner',
        				'class' => 'form-control',
//         		    "required" => "required"
        		)
        ));

        $this->add(array(
        		'name' => 'product_file',
        		'type' => 'file',
        		'attributes' => array(
        				'id' => 'product_file',
        				'class' => 'form-control',
//         		    "required" => "required"
        		)
        ));

        // File Input
        $file = new \Zend\Form\Element\File('image');
        $file->setAttributes(array('multiple' => true));
        $this->add($file);


        $this->add(array(
            'name' => 'price',
            'type' => 'Zend\Form\Element\Number',
            'attributes' => array(
                'id' => 'price',
                'class' => 'form-control',
                'min' => '0',
                'max' => '10000000',
                "required" => "required",
                'step' => '1', // default step interval is 1
            )
        ));
        $this->add(array(
        		'name' => 'code',
        		'type' => 'Text',
        		'attributes' => array(
        				'id' => 'code',
        				'class' => 'form-control',
        		        "required" => "required"
        		)
        ));
        $this->add(array(
            'name' => 'submit',
            'attributes' => array(
                'type'  => 'submit',
                'value' => 'Go',
                'id' => 'submitbutton',
            ),
        ));

        $this->addInputFilter();
    }
    public function addInputFilter()
    {
    	$inputFilter = new InputFilter\InputFilter();

    	// File Input
    	$fileInput = new InputFilter\FileInput('banner');
        $fileInput->setRequired(true);

    	   	$fileInput->getFilterChain()->attachByName('filerenameupload', array(
            'target' => $_SERVER['DOCUMENT_ROOT'] . 'product/banner.png',
            'randomize' => true,
            'overwrite' => true,
            'use_upload_name' => true
        ));

        $inputFilter->add($fileInput);

        $this->setInputFilter($inputFilter);


        //
        $inputFilterProductFile = new InputFilter\InputFilter();

        // File Input
        $fileInputProduct= new InputFilter\FileInput('product_file');
        $fileInputProduct->setRequired(true);

        $fileInputProduct->getFilterChain()->attachByName('filerenameupload', array(
        		'target' => $_SERVER['DOCUMENT_ROOT'] . 'product/product_file.png',
        		'randomize' => true,
        		'overwrite' => true,
        		'use_upload_name' => true
        ));

        $inputFilterProductFile->add($fileInputProduct);

        $this->setInputFilter($inputFilterProductFile);
        //

        $inputFilterImg = new InputFilter\InputFilter();

        // File Input
        $fileInputImg= new InputFilter\FileInput('image');
        $fileInputImg->setRequired(true);

        $fileInputImg->getFilterChain()->attachByName('filerenameupload', array(
        		'target' => $_SERVER['DOCUMENT_ROOT'] . 'product/image.png',
        		'randomize' => true,
        		'overwrite' => true,
        		'use_upload_name' => true
        ));

        $inputFilterImg->add($fileInputImg);

        $this->setInputFilter($inputFilterImg);
    }

}